﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace _13.HappyNumbersInSequence
{
    public class TestGenerator
    {
        static Random random;
        const int minLength = 4500;
        const int maxLength = 5000;
        const int minMember = -1;
        const int maxMember = 10;
        const int nMin = -1;
        const int nMax = 20;

        public static void CreateTest(string inputFileName)
        {
            string sequence = CreateSequence();
            PrintInput(@"..\..\Tests\" + inputFileName,sequence);
        }

        public static string CreateSequence()
        {
            random = new Random();
            StringBuilder test = new StringBuilder();
            test.AppendLine(random.Next(nMin, nMax).ToString());
            int sequenceLength = random.Next(minLength,maxLength);

            int member = random.Next(minMember, maxMember);
            for (int i = 0; i < sequenceLength - 1; i++)
            {
                test.Append(member + " ");
                member = random.Next(minMember, maxMember);
            }
            test.Append(member);

            return test.ToString();
        }

        private static void PrintInput(string fileName, string sequence)
        {
            StreamWriter writer = new StreamWriter(fileName);

            using (writer)
            {
                writer.WriteLine(sequence);
            }
        }
    }
}
